package cn.iocoder.yudao.module.wine.controller.admin.suggest;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.wine.controller.admin.suggest.vo.*;
import cn.iocoder.yudao.module.wine.service.suggest.SuggestService;

@Tag(name = "管理后台 - 用户建议")
@RestController
@RequestMapping("/wine/suggest")
@Validated
public class SuggestController {

    @Resource
    private SuggestService suggestService;

    @PostMapping("/create")
    @Operation(summary = "创建用户建议")
    @PreAuthorize("@ss.hasPermission('wine:suggest:create')")
    public CommonResult<Long> createSuggest(@Valid @RequestBody SuggestSaveReqVO createReqVO) {
        return success(suggestService.createSuggest(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新用户建议")
    @PreAuthorize("@ss.hasPermission('wine:suggest:update')")
    public CommonResult<Boolean> updateSuggest(@Valid @RequestBody SuggestSaveReqVO updateReqVO) {
        suggestService.updateSuggest(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除用户建议")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('wine:suggest:delete')")
    public CommonResult<Boolean> deleteSuggest(@RequestParam("id") Long id) {
        suggestService.deleteSuggest(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得用户建议")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('wine:suggest:query')")
    public CommonResult<SuggestRespVO> getSuggest(@RequestParam("id") Long id) {
        SuggestRespVO suggestRespVO = suggestService.getSuggest(id);
        return success(suggestRespVO);
    }

    @GetMapping("/page")
    @Operation(summary = "获得用户建议分页")
    @PreAuthorize("@ss.hasPermission('wine:suggest:query')")
    public CommonResult<PageResult<SuggestRespVO>> getSuggestPage(@Valid SuggestPageReqVO pageReqVO) {
        PageResult<SuggestRespVO> pageResult = suggestService.getSuggestPage(pageReqVO);
        return success(pageResult);
    }

//    @GetMapping("/export-excel")
//    @Operation(summary = "导出用户建议 Excel")
//    @PreAuthorize("@ss.hasPermission('wine:suggest:export')")
//    @OperateLog(type = EXPORT)
//    public void exportSuggestExcel(@Valid SuggestPageReqVO pageReqVO,
//              HttpServletResponse response) throws IOException {
//        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
//        List<SuggestDO> list = suggestService.getSuggestPage(pageReqVO).getList();
//        // 导出 Excel
//        ExcelUtils.write(response, "用户建议.xls", "数据", SuggestRespVO.class,
//                        BeanUtils.toBean(list, SuggestRespVO.class));
//    }

}
